package controller;

import entity.Atm;
import service.AtmService;
import util.MySpring;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class DoRegist extends HttpServlet {
    AtmService atmService = MySpring.getBean("service.AtmService");

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("DoRegist.doPost");
        request.setCharacterEncoding("UTF-8");
//        String apassword = request.getParameter("apassword");
//        String abalance = request.getParameter("abalance");
//        System.out.println("apassword = " + apassword);
//        System.out.println("abalance = " + abalance);

        String testKey1 = request.getParameter("testKey1");
        String testKey2 = request.getParameter("testKey2");
        String testKey3 = request.getParameter("testKey3");
        System.out.println("testKey1 = " + testKey1);
        System.out.println("testKey2 = " + testKey2);
        System.out.println("testKey3 = " + testKey3);

        Enumeration en = request.getParameterNames();
        while (en.hasMoreElements()) {
            String element = (String) en.nextElement();
            String parameter = request.getParameter(element);
//            System.out.println("DoRegist.doPost element -》"+element+"  //param-》"+parameter);

            Atm atm = (Atm) request.getAttribute("atm");
            System.out.println("atm = " + atm);
            atmService.insert(atm);
            request.getRequestDispatcher("wel.jsp").forward(request, response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("DoRegist.doGet");
    }
}
